package 力扣题库;

public class p112路径总和 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        //递归
        if (root == null) {
            return false;
        }

        if (root.left==null && root.right==null) {
            return targetSum-root.val==0;
        }

        boolean leftTree=hasPathSum(root.left,targetSum-root.val);
        boolean rightTree=hasPathSum(root.right,targetSum-root.val);

        return leftTree || rightTree;
    }
}
